home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / qbnws201.zip / PSHOP.ZIP / PSHOP.BAS < prev   
BASIC Source File  |  1991-01-21  |  8KB  |  173 lines

  1. ' =======================================================================
  2. '  Name:  PSHOP.BAS
  3. '  Ver:   1.10
  4. '  Date:  1/21/1991
  5. '  Lang:  Microsoft QuickBASIC v4.00+.  Optional PDQ.
  6. '  Purp:  Read a *Print Shop* graphics file and display the icon on
  7. '      the screen.  Originally, I designed this to default to VGA
  8. '      such that it could be compiled with PDQ.  By request from your
  9. '      QBNews Editor, however, I have designed it to work with the
  10. '      CGA SCREEN 2 ("high res") mode, black and white.  If you would
  11. '      like to use this utility with PDQ, comment out all of the PSET
  12. '      statements and uncomment the DEF SEG statement and one of the
  13. '      two POKE statements that display the image.  As it now stands,
  14. '      PSHOP will work in the QB environment.  Be sure, though, that
  15. '      you have set the COMMAND$ to the appropriate file name.
  16. '
  17. '      Also, version 1.10 includes a switch (/n) which will allow
  18. '      you to display even the New Print Shop (supposedly higher
  19. '      resolution) images.  Dave Cleary informed me that a 10 byte
  20. '      header exists in the beginning of each PS *file* (not image)
  21. '      such that by initially bypassing this header, the files are
  22. '      read exactly the same as the old printshop graphics.
  23. '  Note:  THIS ROUTINE WILL NOT WORK ON Print Master FILES!  PM files
  24. '         have a delimiter in them denoted by CHR$(11)+CHR$(52)+CHR$(88)
  25. '         which tells about the image type and also truncates a part
  26. '         of the 572 byte block.  Use a conversion utility to convert
  27. '         your PM files to PS before reading with this routine!
  28. '  Kudos: Richard Randless for the GetBit% routine (the one here is a
  29. '         modification for this specific program).  Ryan Snodgrass for
  30. '         the original from which this code is based.  I spent about
  31. '         12 hours analyzing the files and their format, and really
  32. '         simplified this code a lot.  Ryan did not comment his
  33. '         program at all.  Here, I have done so such that it should make
  34. '         a little more sense.  (C)opyright 1991 by Mike Welch and Ryan
  35. '         Snodgrass.  Submitted to the public domain and the QBNews
  36. '         but the Copyright is reserved.  
  37. ' =======================================================================
  38. DEFINT A-Z                    ' we'll use integers mostly
  39. DECLARE FUNCTION GetBit%(Byte%, BPos%)        ' BitRead routine
  40.  
  41. 'GrafFile$ = UCASE$(COMMAND$)            ' use this if PDQ!!!
  42. GrafFile$ = COMMAND$                ' search command line
  43. IF LEN(GrafFile$) = 0 THEN            ' if no file given
  44.    PRINT
  45.  
  46.    ' PRINT "PSHOP - Read and display PrintShop icons on VGA"   ' unREM if PDQ
  47.  
  48.    PRINT "PSHOP - Read and display PrintShop icons on CGA"    ' as defaults
  49.    PRINT "(C)opyright 1991 by Mike Welch and Ryan Snodgrass"
  50.    PRINT "Use /n when displaying New Print Shop graphics"
  51.    PRINT
  52.    PRINT "Syntax:  PSHOP Filename.dat [/n]"
  53.    END
  54. END IF
  55.  
  56. ' Check for the /N[ew] switch and act accordingly
  57. x% = INSTR(GrafFile$, "/N")            ' check for /n[ew] PS
  58. IF x% THEN                    ' switch was passed
  59.    GrafFile$ = RTRIM$(MID$(GrafFile$, 1, x% - 1))    ' strip /n from name
  60.    n% = -1                    ' set boolean value
  61. END IF
  62.  
  63. 'SCREEN 13                    ' use this if using PDQ
  64. SCREEN 2                    ' "high" [low] res CGA mode
  65.  
  66. ' Uncomment the following code if you're using VGA and PDQ.  It
  67. ' will be useless in regular QuickBASIC!
  68. 'IF ERR THEN            ' if not a VGA system
  69. '   PRINT
  70. '   PRINT "Sorry, this PDQ-compiled version requires a VGA!"
  71. '   END
  72. 'END IF
  73.  
  74. ' Uncomment this if you are using the PDQ version/option
  75. 'DEF SEG = &HA000        ' this is for POKEing in VGA memory
  76.  
  77. ' If you're using PDQ, you'll want to include the following
  78. 'COLOR 0, 0                ' unremark if using PDQ!!!
  79.  
  80.  
  81. OPEN GrafFile$ FOR BINARY AS 1 LEN = 572    ' open PS file
  82. SizeF& = LOF(1)                    ' get it's length
  83. TotalPics% = SizeF& \ 572            ' how many icons?
  84. ' If the /n[ew] switch was present, the boolean flag n%
  85. ' will have a non-zero value.  If so, we should strip
  86. ' the first 10 bytes from the "New Print Shop" file
  87. ' at the beginning.  All else works the same!
  88. IF n% THEN Temp$ = INPUT$(10, #1)        ' strip 10-byte header
  89. FOR DoAll% = 1 TO TotalPics%            ' process them all
  90.    x% = 0: Y% = 1                ' initialize coords
  91.    Temp$ = INPUT$(572, #1)            ' read 1 icon
  92.    FOR i% = 1 TO 572                ' process all bytes
  93.      Pix% = ASC(MID$(Temp$, i%, 1))        ' get 1 byte value
  94.      FOR k% = 0 TO 7                ' process 8 bits
  95.       Bit% = GetBit%(Pix%, k%)        ' Bit% is 0 or 1
  96.     ' Here, I hard code the colors.  Change
  97.     ' as desired.  Refer to the SCREEN and
  98.     ' COLOR areas of the QB manual for what
  99.     ' can be legally accomplished
  100.  
  101.     IF Bit% THEN p% = 0 ELSE p% = 1
  102.     'IF Bit% THEN p% = 1 ELSE p% = 15    ' set colors for VGA
  103.  
  104.     ' UnREMark what follows as desired.  I
  105.     ' have included two options.  One centers the
  106.     ' image on the screen, the other in the left.
  107.     ' Also, you can just add to the x% +... and
  108.     ' the y% +... values to position the icon whereever
  109.     ' you want it, with the PSET statement!  The second
  110.     ' PSET statement centers the icon in SCREEN 2.  Use
  111.     ' only one PSET though!
  112.     'PSET (x% + 7 - k%, y%), p%        ' print in left corner
  113.  
  114.     PSET (x% + 7 - k% + 276, y% + 74), p%    ' center for SCREEN 2
  115.  
  116.     'POKE (y% - 1) * 320& + (x% + 7 - k%), p% ' write pixel at left VGA
  117.     'POKE (y% - 1 + 74) * 320& + (x% + 7 - k% + 116), p%  ' CENTER VGA
  118.      NEXT k%                    ' next BIT
  119.      ' Although at this time we've actually only read 1 byte,
  120.      ' it has been translated into 8 bit values, where each
  121.      ' bit represents a pixel (on or off: 1 or 0).  Therefore,
  122.      ' we must move the x-coordinate value over 8 places to
  123.      ' compensate for this bit reading.  This part in particular
  124.      ' was a tough one to analyze!  Also, if we've processed
  125.      ' 11 bytes (11 * 8Bits = 88 pixels, which is the column value
  126.      ' for all of the older PM/PS icons) then x% will be > than 87
  127.      ' [or x% will = 88, whatever] so we need to move to the
  128.      ' next "row."  This explains the y% = y% + 1 below.
  129.      x% = x% + 8                ' move COLUMN
  130.      IF x% > 87 THEN                ' if end of 1 column
  131.          x% = 0                    ' reset column value
  132.      y% = y% + 1                ' go to next ROW
  133.      END IF
  134.    NEXT i%                    ' loop for all of icon
  135.  
  136.    ' Usage note:  Press a key after each icon is printed.  If you
  137.    ' press the ESC key, the program terminates.
  138.    DO
  139.     KeyCk$ = INKEY$            ' check for keypress
  140.    LOOP UNTIL LEN(KeyCk$)        ' loop until keypress
  141.    IF KeyCk$ = CHR$(27) THEN EXIT FOR    ' if pressed ESC, exit loop
  142.    CLS                    ' erase old pixel
  143. NEXT DoAll                ' next picture/icon
  144. 'DEF SEG                ' ret DGROUP, unREM if using PDQ/VGA
  145. SCREEN 0                ' back to screen 0, text mode
  146. END                    ' end program here
  147.  
  148. ' ======================================================
  149. '  Name:    GetBit%
  150. '  Type:    FUNCTION
  151. '  Lang:    Microsoft QuickBASIC 4.00+
  152. '  Date:    Sept. 1990
  153. '  Vers:    1.00m
  154. '  By:      Richard Randles
  155. '  Purp:    Check the bit status of any BYTE.  This is
  156. '        a modified version of the WORD GetBit%.
  157. '  Syntax:  OneOrZero% = GetBit%(Byte%, BPos%)
  158. '  Notes:   Does not process negative numbers.  This
  159. '           routine is specific to PSHOP.BAS and is
  160. '           designed to get the bit value of an unsigned
  161. '           byte value, range 0-255 only.
  162. ' ======================================================
  163. '
  164. FUNCTION GetBit%(Byte%, BPos%)
  165.  
  166. Work% = Byte%            ' backup 2 byte variable
  167. FOR BitC% = 1 TO BPos%        ' BPos% range is 0 to 7
  168.    Work% = Work% \ 2        ' shift bits right BPos% times
  169. NEXT
  170. GetBit% = Work% AND 1        ' return Boolean: ON or OFF
  171.  
  172. END FUNCTION
  173.